package com.lotter.common.util;

import com.lotter.common.exception.LotterCusException;

/**
 * 计算 主要是资金计算
 * @author zhangzechi
 *
 */
public class LongUtil {
	
	
	//相加  
	public static Long add(Long... args){
		if(args.length == 0)
			return null;
		
		Long ret = new Long(0);
		for (Long lo : args) {
			if (lo != null) {
				ret += lo;
			}
		}
		return ret;
	}
	
	
	/**
	 * 减法  第一位是被减数  其他都是减数
	 * @param args
	 * @return
	 * @throws LotterCusException
	 */
	public static Long sub(Long... args) throws LotterCusException{
		if(args.length == 0)
			return null;
		if(args.length == 1)
			return args[0];
		Long ret = args[0];
		for(int i = 1 ; i <args.length ;i ++){
			ret -= args[i];
		}
		if(ret.longValue() < 0){
			throw new LotterCusException("计算错误");
		}
		return ret ;
	}
	
	//对比两组数据
	public static int compare(Long former,Long contrast) throws LotterCusException{
		if(former == null || contrast ==null){
			throw new LotterCusException();
		}
		if(former.longValue() > contrast.longValue() ){
			return 1;
		}else if(former.longValue() < contrast.longValue()){
			return -1 ;
		}else{
			return 0 ;
		}
	}
	
	
	public static void main(String[] args) {
		System.out.println(sub(2000000l,4l,5l));
	}

	
	/*BigDecimal ret = BigDecimal.ZERO;
	for (Long lo : args) {
		if (lo != null) {
			ret = ret.add(new BigDecimal(lo));
		}
	}
	ret.setScale(0, BigDecimal.ROUND_HALF_UP);
	return ret.longValue() ;*/
}
